package Units;

import org.lwjgl.opengl.GLSync;
import org.lwjgl.util.glu.Sphere;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glScalef;

import Game.GameObject;

public class CannonBall extends GameObject{
	
	Sphere shape = new Sphere();
	private long createTime;
	private float ang = 90;
	private float vel = 90;
	public String parentName;
	
	public CannonBall(float x,float  y,float  z, float ang, String parentName) {
		super(x, y, z);
		rotateY = ang;
		createTime = System.currentTimeMillis();
		this.parentName = parentName;
	}

	@Override
	public void Update(long diftime) {
		if(System.currentTimeMillis() - createTime > 5000)
			alive = false;
		
		double radians = (Math.PI/180)*this.rotateY;
		x += ((float)Math.cos((double)radians) * vel) * diftime / 1000;
		z += (((float)Math.sin((double)radians) * vel) * diftime / 1000)*-1;
	}

	@Override
	public void Render() {
		glPushMatrix();
		glScalef(0.5f, 0.5f, 0.5f);
		shape.draw(2, 10, 10);
		glPopMatrix();
	}
	
}
